
{extend name="layout"}
{block name="title"}编辑保险状态{/block}
{block name="style"}

<link rel="stylesheet" type="text/css" href="__ROOT__/static/personal/css/weui.min.css"/>
<!--<link rel="stylesheet" type="text/css" href="__ROOT__/static/personal/css/jquery-weui.css"/>-->
<style type="text/css">
	.toolbar .toolbar-inner {
		height: 1.067rem !important;

	}
	.toolbar .title {

		font-size: 0.373rem !important;
		line-height: 1.067rem !important;

	}
	.toolbar .picker-button {
		height: 1.067rem !important;
		line-height: 1.067rem !important;
		color: #0998FF !important;

	}
	.weui_cell {
		padding: 0.267rem 0.4rem !important;

	}
	.weui_cell_primary p{
		font-size: 0.373rem !important;
	}
	.weui_cells_radio .weui_check:checked+.weui_icon_checked:before {

		color: #0998FF !important;
	}

</style>
{/block}
{block name="body"}

<div class="type-content">
		<div class="type-box">
			{notempty name='increase_insurances'}
			{foreach $increase_insurances as $key=>$vo}
			<div class="input-type">
				<p>{$vo.insurance_cn|default=''}</p>
				<input data-id="{$vo.id|default=0}" name="{$vo.insurance|default=''}" type="text"
					   data-values="{$vo.hand_type|default=''}" value=""
					   placeholder="请选择">
				<span class="iconfont icon-a-lujing2245"></span>

			</div>
			{/foreach}
			{/notempty}
			<!--<div>
				<p>工伤保险</p>

				<input name="injury" type="text" value=""  placeholder="请选择">
				<span class="iconfont icon-a-lujing2245"></span>

			</div>
			<div>
				<p>医疗保险</p>

				<input name="medical" type="text" value=""  placeholder="请选择">
				<span class="iconfont icon-a-lujing2245"></span>

			</div>
			<div>
				<p>住房公积金</p>

				<input name="fund" type="text" value=""  placeholder="请选择">
				<span class="iconfont icon-a-lujing2245"></span>

			</div>-->

			<input type="hidden" name="id" value="{$id|default=0}">

			<button onclick="submitType()">确定</button>
		</div>



</div>

{/block}
{block name="script"}

<script>
	var getOption = function (){
		//


		$.ajax({
			url: '{:url("handtype_option")}',

			type: "get",
			success: function(res) {
				if(res.code == 1) {


					$("[name='1']").select({
						title: "选择保险状态",
						items:res.data.yanglao,

					});
					$("[name='2']").select({
						title: "选择保险状态",
						items: res.data.gongshang
					});
					$("[name='3']").select({
						title: "选择保险状态",
						items: res.data.shiye
					});
					$("[name='4']").select({
						title: "选择保险状态",
						items: res.data.yiliao
					});
					$("[name='5']").select({
						title: "选择保险状态",
						items: res.data.gongjijin
					});

					$.each(res.data.yanglao,function (i,item){
						if(item.value == $("[name='1']").attr('data-values') ){
							$("[name='1']").val(item.title)
						}
					})
					$.each(res.data.gongshang,function (i,item){
						if(item.value == $("[name='2']").attr('data-values') ){
							$("[name='2']").val(item.title)
						}
					})
					$.each(res.data.shiye,function (i,item){
						if(item.value == $("[name='3']").attr('data-values') ){
							$("[name='3']").val(item.title)
						}
					})
					$.each(res.data.yiliao,function (i,item){
						if(item.value == $("[name='4']").attr('data-values') ){
							$("[name='4']").val(item.title)
						}
					})
					$.each(res.data.gongjijin,function (i,item){
						if(item.value == $("[name='5']").attr('data-values') ){
							$("[name='5']").val(item.title)
						}
					})


				} else {
					layer.msg(res.info)
				}
			},
			error: function() {
				layer.msg("发生错误~");
			}
		});
	}
	isSubmit = true
	var submitType = function (){
		//
		if(isSubmit) {
			isSubmit = false
			setTimeout(function () {
				isSubmit = true
			}, 2000)
			var params = {types:{}}

			isFlag = false


			$('.input-type').each(function (){

				if(isFlag) return;

				var _name = $(this).find('input').attr('name')
				var _value = $("[name='"+ _name +"']").attr('data-values')
				console.log(_name)
				console.log(_value)
				if(_value == "0"){
					switch(_name) {
						case '1':
							layer.msg("请选择养老保险状态~！");
							isFlag = true
							break;
						case '2':
							layer.msg("请选择工伤保险状态~！");
							isFlag = true
							break;
						case '3':
							layer.msg("请选择失业保险状态~！");
							isFlag = true
							break;
						case '4':
							layer.msg("请选择医疗保险状态~！");
							isFlag = true
							break;
						case '5':
							layer.msg("请选择住房公积金状态~！");
							isFlag = true
							break;

					}

				}else{


					params["types"][_name] = $(this).find('input').attr('data-id') + "," +$(this).find('input').attr('data-values')
				}

			})

			if(isFlag) return;
			console.log(params)

			params['id'] = $("[name='id']").val()
			$.ajax({
				url: '{:url("handtype")}',
				data: params,
				type: "post",
				success: function(res) {
					if(res.code == 1) {
						window.location.href="index.html"
					} else {
						layer.msg(res.info)
					}
				},
				error: function() {
					layer.msg("发生错误~");
				}
			});
		}

	}
	require(['jquery','weui'],function($){

		getOption()

	})





</script>
{/block}
